package com.junxonline.plat.dao.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * @ClassName: User
 * @Description: 用户数据模型
 * @author JunX
 */

@Entity
@Table(name = "sys_user")
@JsonIgnoreProperties({"roles", "positions", "devices", "deviceChecks", "attences"})
public class User implements java.io.Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long userId;

    /**
     * 用户名
     */
    @Column(nullable = false)
    private String username;

    /**
     * 密码
     */
    @Column(nullable = false)
    private String password;

    /**
     * 昵称
     */
    @Column(nullable = false)
    private String nickname;

    /**
     * 性别
     */
    @Column(nullable = false)
    private Integer sex;

    @Transient
    private String sexString;

    /**
     * 手机号码
     */
    @Column
    private String phone;

    /**
     * 邮箱
     */
    @Column
    private String email;

    /**
     * 个人说明
     */
    @Column
    private String description;

    /**
     * 注册时间
     */
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(nullable = false)
    private Date createTime;

    /**
     * 最后登录时间
     */
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @Column
    private Date lastLoginTime;

    /**
     * 最后登录IP
     */
    @Column
    private String lastLoginIp;

    /**
     * 状态
     */
    @Column(nullable = false)
    private Integer status;

    @Transient
    private String statusString;

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "sys_user_role", joinColumns = { @JoinColumn(name = "userId") }, inverseJoinColumns ={@JoinColumn(name = "roleId") })
    private List<Role> roles;

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "sys_user_position", joinColumns = { @JoinColumn(name = "userId") }, inverseJoinColumns ={@JoinColumn(name = "positionId") })
    private List<Position> positions;

    @Transient
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    private List<Device> devices;

    @Transient
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    private List<DeviceCheck> deviceChecks;

    @Transient
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    private List<Attence> attences;

    public User() {

    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    public String getSexString() {
        return sexString;
    }

    public void setSexString(String sexString) {
        this.sexString = sexString;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(Date lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public String getLastLoginIp() {
        return lastLoginIp;
    }

    public void setLastLoginIp(String lastLoginIp) {
        this.lastLoginIp = lastLoginIp;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getStatusString() {
        return statusString;
    }

    public void setStatusString(String statusString) {
        this.statusString = statusString;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public List<Position> getPositions() {
        return positions;
    }

    public void setPositions(List<Position> positions) {
        this.positions = positions;
    }

    public List<Device> getDevices() {
        return devices;
    }

    public void setDevices(List<Device> devices) {
        this.devices = devices;
    }

    public List<DeviceCheck> getDeviceChecks() {
        return deviceChecks;
    }

    public void setDeviceChecks(List<DeviceCheck> deviceChecks) {
        this.deviceChecks = deviceChecks;
    }

    public List<Attence> getAttences() {
        return attences;
    }

    public void setAttences(List<Attence> attences) {
        this.attences = attences;
    }
}
